#ifndef SRVIFACE_H
#define SRVIFACE_H

/**
* A class that defines the server interface
*/
class ServerInterface
{
	public:
		/**
		* A constructor
		*
		* @param port port address to listen on
		*/
		ServerInterface(int port);

		/**
		* A deconstructor
		*/
		virtual ~ServerInterface() { }

		/**
		* Returns true if the server intializes
		*
		* @return true if the server intializes
		*/

		virtual bool8 initSuccess() { return true; }

		/**
		* Starts the server
		*/
		virtual void run() = 0;
	
		/**
		* Stops the server
		*/
		virtual void stop() = 0;

		/**
		* Sets the stop messages sent to the client when the server shuts down
		* 
		* @param Msg message sent to the client
		*/
		void setStopMsg(char *Msg);

		/**
		* Returns the stop message sent to the client
		*
		* @return the stop message sent to the client
		*/
		char* getStopMsg();

		/**
		* Returns true if the server is currently stopping
		*
		* @return true if the server is currently stopping
		*/
		bool8 isStopping();

		/**
		* Returns a random number
		*
		* @return random number
		*/		
		virtual uint32 rand() { return 0; }

	protected:
		enum Constants { STOPMSGMAX = 30 };		/**< max length of the stop messsage 	*/ 
		int32	port;							/**< port address to listen on 			*/ 
		int32	stopping;						/**< true if the server is stopping 	*/ 
		char	stopMsg[STOPMSGMAX + 1];		/**< stop message 						*/ 
};

inline
ServerInterface::ServerInterface(int port)
{
	this->port = port;
	stopping = false;
	stopMsg[0] = '\0';
}

inline bool8
ServerInterface::isStopping()
{
	return (bool8)(stopping != 0);
}

inline char*
ServerInterface::getStopMsg()
{
	return stopMsg;
}

#endif
